MySQL specifying exact order with WHERE `id` IN (...)

Posted by Gray Fox on Stack Overflow See other posts from Stack Overflow or by Gray Fox
Published on 2010-06-02T13:21:40Z Indexed on 2010/06/02 13:24 UTC
Read the original article Hit count: 212

Filed under:
|
|

Is there an easy way to order MySQL results respectively by WHERE id IN (...) clause? Example:

SELECT * FROM articles WHERE articles.id IN (4, 2, 5, 9, 3)

to return

Article with id = 4
Article with id = 2
Article with id = 5
Article with id = 9
Article with id = 3

and also

SELECT * FROM articles WHERE articles.id IN (4, 2, 5, 9, 3) LIMIT 2,2

to return

Article with id = 5
Article with id = 9

© Stack Overflow or respective owner

Related posts about mysql

Related posts about order-by